package com.mine.androidlearn.api.Interceptor;


import com.mine.androidlearn.api.exception.NetworkNotConnectedException;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * 网络状态拦截器
 *
 * @author mine
 * @version V1.0 2018/8/6 22:33
 */
public class NetworkStateInterceptor<T extends NetworkMonitor> implements Interceptor {

    private final T mMonitor;

    public NetworkStateInterceptor(T t) {
        mMonitor = t;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        if (!mMonitor.isConnected()) {
            throw new NetworkNotConnectedException();
        }

        return chain.proceed(chain.request());
    }
}
